import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
 * Created by :Infaraway
 * DATE : 2017/3/25
 * Time : 14:34
 * Funtion : session对象的获取
 */
public class GetSession extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//1.得到session对象
		HttpSession session = request.getSession(false);

		if(session==null){
			System.out.println("没有找到对应的sessino对象");
			return;
		}
		//得到session编号
		System.out.println("id="+session.getId());

		//2.取出数据
		String name = (String)session.getAttribute("name");
		System.out.println("name="+name);
	}
}

